import mcApi from 'mc-c2b2m-operator-api';
import { TreeSelect } from 'ant-design-vue';
import { BasicColumn, FormSchema } from '@/components/Table';

const { SystemModule } = mcApi;
const { DepartmentApi } = SystemModule;

export const tableColumns: BasicColumn[] = [
  {
    title: '部门名称',
    dataIndex: 'name',
  },
  {
    title: '上级部门',
    dataIndex: 'parentName',
  },
  {
    title: '创建时间',
    dataIndex: 'createdTime',
  },
  {
    title: '更新时间',
    dataIndex: 'updatedTime',
  },
];
export const tableFormSchema: FormSchema[] = [];

export const modalFormSchema: FormSchema[] = [
  {
    ifShow: false,
    field: 'id',
    label: 'id',
    component: 'Input',
  },
  // {
  //   required: true,
  //   field: 'org',
  //   label: '所属组织',
  //   component: 'ApiSelect',
  //   componentProps: {},
  // },
  {
    // required: true,
    field: 'parentId',
    label: '上级部门',
    component: 'ApiTreeSelect',
    componentProps: ({ formActionType }) => {
      const { setFieldsValue } = formActionType;
      return {
        showSearch: true,
        valueField: 'id',
        labelField: 'name',
        treeCheckStrictly: true,
        treeDefaultExpandAll: true,
        treeNodeFilterProp: 'name',
        childrenField: 'childDeptList',
        api: DepartmentApi.getAllDepartmentOfOrg,
        showCheckedStrategy: TreeSelect.SHOW_ALL,
        onSelect: async (_, node: any) => {
          // 调整为单选操作
          const { id, name } = node;
          await setFieldsValue({ parentId: id ? [{ label: name, value: id }] : [] });
        },
      };
    },
  },
  {
    required: true,
    field: 'name',
    label: '部门名称',
    component: 'Input',
  },
];
